<?php
//error_reporting(0);
include("../connection/connection.php");
include("reportFunctions.php");
$distId=$_REQUEST['distId'];
$sqlReport = "SELECT distinct `district_id`,`district_name`,`block_id`,`block_name` FROM `tbl_lookup_location` where `district_id` = ".$distId." group by `block_id`";
$queryReport = mysql_query($sqlReport);

function getDesignPopWater($hp,$distId,$blockId) {
$sqlgetSchemeNoDistWise="SELECT sum($hp) FROM tbl_dtls_q2_main where district_id=".$distId." and block_id=".$blockId;
$querygetSchemeNoDistWise=mysql_query($sqlgetSchemeNoDistWise);
$arrCountSource=mysql_fetch_row($querygetSchemeNoDistWise);
return $arrCountSource[0];
//echo $sqlgetSchemeNoDistWise;
}

/*function getHpNo($distId,$blockId)
{
	$sqlgetHpNo="SELECT sum(hp_no) FROM `tbl_dtls_q2_main` main,tbl_dtls_q2_habit hab WHERE hab.q2_id=main.id and district_id=".$distId." and block_id=".$blockId;
$querygetHpNo=mysql_query($sqlgetHpNo);
$arrCountHpSource=mysql_fetch_row($querygetHpNo);
return $arrCountHpSource[0];

}*/

?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Block</title>
</head>
<body>
<table border="0" width="900" cellspacing="0" cellpadding="0">
	<tr>
		<td bgcolor="#E9E9E9" height="26">
		<p align="center"><span style="font-size: 9pt; font-weight: 700">
		<font face="Verdana" color="#224568">Block wise Source details and their status (as per PHED)</font></span>
        <div align="center"><span style="font-size: 9pt; font-weight: 700"><font face="Verdana" color="#224568">Table 14</font></span></div>
        </td>
	</tr>
	<tr>
		<td bgcolor="#E9E9E9" height="56">
		<table border="1" width="900" cellspacing="0" cellpadding="0" height="121" bgcolor="#C5D8EB">
			<tr>
				<td width="80" rowspan="2" align="center">
				<font style="font-size: 8.5pt" face="Verdana">Name of Block</font></td>
				<td width="52" rowspan="2" align="center">
				<p align="center"><font face="Verdana" style="font-size: 8.5pt">
				Type of Sources</font></td>
				<td width="68" rowspan="2" align="center">
				<font style="font-size: 8.5pt" face="Verdana">Total number of sources</font></td>
				<td height="31" colspan="2" align="center">
				<font style="font-size: 8.5pt" face="Verdana">Pumps (no.)</font></td>
				<td width="61" rowspan="2" align="center">
				<font face="Verdana" style="font-size: 8.5pt">Designed population</font></td>
				<td width="61" rowspan="2" align="center">
				<font face="Verdana" style="font-size: 8.5pt">Design Water Demand (KLD)</font></td>
				<td width="60" rowspan="2" align="center">
				<font face="Verdana" style="font-size: 8.5pt">Current Population (2010)</font></td>
				<td width="63" rowspan="2" align="center">
				<font face="Verdana" style="font-size: 8.5pt">Current Water Demand (KLD)<font color="#FF0000"></font></font></td>
                <td width="63" rowspan="2" align="center">
				<font face="Verdana" style="font-size: 8.5pt">Sum of maximum yield in KLD</font></td>
            </tr>
			<tr>
			  <td align="center"><font face="Verdana" style="font-size: 8.5pt">Handpumps</font></td>
		      <td align="center"><font face="Verdana" style="font-size: 8.5pt">Single Phase Pumps</font></td>
		  </tr>
			<?php
			
			while($rowReport = mysql_fetch_array($queryReport)) {
			if(($rowReport['district_id']==389) || ($rowReport['district_id']==390) || ($rowReport['district_id']==391) || ($rowReport['district_id']==392) || ($rowReport['district_id']==401) || ($rowReport['district_id']==402) || ($rowReport['district_id']==403) || ($rowReport['district_id']==404) || ($rowReport['district_id']==405) || ($rowReport['district_id']==406) || ($rowReport['district_id']==416))
			{
			$lpcd=70;
			}else{
			$lpcd=40;
			}
			$no_hp=getTotalFunctionalStatusNoBlockWise($distId,$rowReport['block_id']);
			$current_pop_hp=getPopulationSchemeBlockWise($distId,'HP',$rowReport['block_id']);
			$water_demand_hp=number_format(($current_pop_hp*$lpcd)/1000,2,'.','');
			$design_pop_hp=round(getDesignPopWater('DP_population',$distId,$rowReport['block_id']));
			$design_water_hp=getDesignPopWater('DP_water_demand',$distId,$rowReport['block_id']);
			
			
			$CurrentPopulation=getSourcesBasedHP('present_population','Open-Well',$rowReport['block_id']);
			$CurrentWaterDemand=number_format(($CurrentPopulation*$lpcd)/1000,2,'.','');
			$CurrentPopulation1=getSourcesBasedHP('present_population','Tube-Well',$rowReport['block_id']);
			$CurrentWaterDemand1=number_format(($CurrentPopulation1*$lpcd)/1000,2,'.','');
			$a=getSources('Open-Well',$rowReport['block_id']);
			$b=getSources('Tube-Well',$rowReport['block_id']);
			$c=getSourcesBasedHP('hp_nos','Open-Well',$rowReport['block_id']);
			$d=getSourcesBasedHP('hp_nos','Tube-Well',$rowReport['block_id']);
			$e=getSourcesBasedHP('sp_nos','Open-Well',$rowReport['block_id']);
			$f=getSourcesBasedHP('sp_nos','Tube-Well',$rowReport['block_id']);
			$g=round(getSourcesBasedHP('population','Open-Well',$rowReport['block_id']));
			$h=round(getSourcesBasedHP('population','Tube-Well',$rowReport['block_id']));
			$i=getSourcesBasedHP('water_demand','Open-Well',$rowReport['block_id']);
			$j=getSourcesBasedHP('water_demand','Tube-Well',$rowReport['block_id']);
			$k=getMaximumYeild('Open-Well',$rowReport['block_id']);
			$l=getMaximumYeild('Tube-Well',$rowReport['block_id']);
			$Total1=$a+$b+$no_hp;
			$Total2=$c+$d;
			$Total3=$e+$f;
			$Total4=$g+$h+$design_pop_hp;
			$Total5=$i+$j+$design_water_hp;
			$Total6=$CurrentPopulation+$CurrentPopulation1+$current_pop_hp;
			$Total7=$CurrentWaterDemand+$CurrentWaterDemand1+$water_demand_hp;
			$Total8=$k+$l;
			
			?>
			
			<tr bgcolor="#FFFFFF">
			  <td width="80" rowspan="3" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $rowReport['block_name'];?></font></td>
				
				<td width="52" height="21" align="center"><font style="font-size: 8.5pt" face="Verdana"> OW</font></td>
				<td width="68" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $a;?></font></td>
				<td width="75" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $c;?></font></td>
				<td width="103" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $e;?></font></td>
				<td width="61" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $g;?></font></td>
				<td width="61" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format(getSourcesBasedHP('water_demand','Open-Well',$rowReport['block_id']),2,'.','');?></font></td>
				<td width="60" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo getSourcesBasedHP('present_population','Open-Well',$rowReport['block_id']);?></font></td>
				<td width="63" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $CurrentWaterDemand;?></font></td>
                <td width="63" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo getMaximumYeild('Open-Well',$rowReport['block_id']);?></font></td>
          </tr>
			<tr bgcolor="#FFFFFF">
			  <td height="23" align="center"><font style="font-size: 8.5pt" face="Verdana">TW</font></td>
		      <td width="68" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $b;?></font></td>
		      <td width="75" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $d;?></font></td>
		      <td width="103" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $f;?></font></td>
		      <td width="61" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $h;?></font></td>
		      <td width="61" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format(getSourcesBasedHP('water_demand','Tube-Well',$rowReport['block_id']),2,'.','');?></font></td>
		      <td width="60" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo getSourcesBasedHP('present_population','Tube-Well',$rowReport['block_id']);?></font></td>
		      <td width="63" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $CurrentWaterDemand1;?></font></td>
		      <td width="63" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo getMaximumYeild('Tube-Well',$rowReport['block_id']);?></font></td>
		  </tr>
		  <tr bgcolor="#FFFFFF">
			  <td height="23" align="center"><font style="font-size: 8.5pt" face="Verdana">HP</font></td>
		      <td width="68" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $no_hp;?></font></td>
		      <td width="75" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php //echo $d;?></font></td>
		      <td width="103" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php //echo $f;?></font></td>
		      <td width="61" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $design_pop_hp;?></font></td>
		      <td width="61" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($design_water_hp,2,'.','');?></font></td>
		      <td width="60" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $current_pop_hp;?></font></td>
		      <td width="63" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $water_demand_hp;?></font></td>
		      <td width="63" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php //echo getMaximumYeild('Tube-Well',$rowReport['block_id']);?></font></td>
		  </tr>
			
			<tr bgcolor="#E9E9E9">
				<td width="80" align="center"><font style="font-size: 8.5pt" face="Verdana">Total</font></td>
				<td align="center" width="52"><font style="font-size: 8.5pt" face="Verdana">&nbsp;</font></td>
				<td align="center" width="68"><font style="font-size: 8.5pt" face="Verdana"><?php echo $Total1;?></font></td>
				<td width="75" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $Total2;?></font></td>
				<td width="103" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $Total3;?></font></td>
				<td width="61" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $Total4;?></font></td>
				<td align="center" width="61"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($Total5,2,'.','');?></font></td>
				<td align="center" width="60"><font style="font-size: 8.5pt" face="Verdana"><?php echo $Total6;?></font></td>
				<td align="center" width="63"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($Total7,2,'.','');?></font></td>
                <td align="center" width="63"><font style="font-size: 8.5pt" face="Verdana"><?php echo $Total8;?></font></td>
            </tr>
            <?php
			$GrandTotal1+=$Total1;
			$GrandTotal2+=$Total2;
			$GrandTotal3+=$Total3;
			$GrandTotal4+=$Total4;
			$GrandTotal5+=$Total5;
			$GrandTotal6+=$Total6;
			$GrandTotal7+=$Total7;
			$GrandTotal8+=$Total8;
			}
			?>
            <tr bgcolor="#E9E9E9">
				<td width="80" align="center"><font style="font-size: 8.5pt" face="Verdana">Grand Total</font></td>
				<td align="center" width="52"><font style="font-size: 8.5pt" face="Verdana">&nbsp;</font></td>
				<td align="center" width="68"><font style="font-size: 8.5pt" face="Verdana"><?php echo $GrandTotal1;?></font></td>
				<td width="75" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $GrandTotal2;?></font></td>
				<td width="103" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $GrandTotal3;?></font></td>
				<td width="61" align="center"><font style="font-size: 8.5pt" face="Verdana"><?php echo $GrandTotal4;?></font></td>
				<td align="center" width="61"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($GrandTotal5,2,'.','');?></font></td>
				<td align="center" width="60"><font style="font-size: 8.5pt" face="Verdana"><?php echo $GrandTotal6;?></font></td>
				<td align="center" width="63"><font style="font-size: 8.5pt" face="Verdana"><?php echo number_format($GrandTotal7,2,'.','');?></font></td>
                <td align="center" width="63"><font style="font-size: 8.5pt" face="Verdana"><?php echo $GrandTotal8;?></font></td>
            </tr>
		</table>
	  </td>
	</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

</body>

</html>

